package com.onluy.plugins.telemanager;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; 
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class clent extends CordovaPlugin {

    CallbackContext rtnCallbackContext=null;
    Handler msgHandler =new Handler(){
        @Override
        public void handleMessage(Message msg) {
             Toast.makeText(cordova.getActivity(), "返回执行结果："+msg.obj.toString(), Toast.LENGTH_SHORT).show();
            if(rtnCallbackContext!=null)
                rtnCallbackContext.success(msg.obj.toString());
        }

    };
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        Toast.makeText(cordova.getActivity(), "执行"+action, Toast.LENGTH_SHORT).show();
        rtnCallbackContext=callbackContext;
        JSONObject info=args.getJSONObject(0);
        if("Tel".equals(action)){
            CellMan.getInstance().setMsgHandler(msgHandler);
            CellMan.getInstance().setOutNumber(info.getString("Phone"));
        }
        return true;
    }

}